/*
ID:luongho3
LANG:JAVA
TASK:milk
 */
package usaco.training.chap1.sec3;

import java.io.File;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class milk {

	static int N, M;
	static farmer[] fs;
	
	public static void main(String[] args) throws Exception {
		Scanner scanner = new Scanner(new File("milk.in"));
		PrintStream ps = new PrintStream(new File("milk.out"));
//		System.setOut(ps);
		N = scanner.nextInt();
		M = scanner.nextInt();
		fs = new farmer[M];
		for (int i=0;i<M;++i) {
			int p, m;
			p = scanner.nextInt();
			m = scanner.nextInt();
			fs[i] = new farmer(p,m);
		}
		Arrays.sort(fs, new Comparator<farmer>() {

			public int compare(farmer o1, farmer o2) {
				return o1.price - o2.price;
			}
			
		});
		int cost = 0;
		int idx = 0;
		while (N > 0) {
			if (N > fs[idx].milk) {
				N -= fs[idx].milk;
				cost += fs[idx].milk * fs[idx].price;
				idx++;
			}
			else {
				cost += fs[idx].price * N;
				N = 0;
			}
		}
		System.out.println(cost);
	}

}
class farmer {
	int price;
	int milk;
	farmer(int price, int milk) {
		this.price = price;
		this.milk = milk;
	}
}